package Dao;

import Modelo.Categoria;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

@Stateless
public class CategoriaDao extends AbstractDao<Categoria> implements CategoriaDaoLocal {
    @PersistenceContext(unitName = "BibliotecaAmalia-ejbPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public CategoriaDao() {
        super(Categoria.class);
    }
    
    @Override
    public boolean findDuplicity(Categoria category) {
        // selecionar consulta
        Query q=em.createNamedQuery("Categoria.findByClave");
        //poner parametros
        q.setParameter("clave", category.getClave());
        //ejecutar la consulta
        return !q.getResultList().isEmpty();
    }
    
}
